package com.cafe.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cafe.dao.CustomerDao;
import com.cafe.model.Customer;
import com.cafe.service.CustomerService;
import com.malamute.core.common.Page;

/**
 * @Description 会员业务接口实现类
 * @version v1.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {

	@Autowired(required = false)
	private CustomerDao customerDao;

	/**
	 * 设置customerDao
	 * 
	 * @param customerDao
	 */
	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param customer
	 * 
	 * @see
	 * com.cafe.business.CustomerService#registerCustomer(com.cafe.model.Customer
	 * )
	 */
	@Override
	public void registerCustomer(Customer customer) {
		customerDao.save(customer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param customer
	 * 
	 * @see
	 * com.cafe.business.CustomerService#addCustomer(com.cafe.model.Customer)
	 */
	@Override
	public void saveCustomer(Customer customer) {
		customerDao.save(customer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param id
	 * 
	 * @return
	 * 
	 * @see com.cafe.business.CustomerService#getCustomerById(long)
	 */
	@Override
	public Customer getCustomerById(int id) {

		return (Customer) customerDao.get(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param customer
	 * 
	 * @see
	 * com.cafe.business.CustomerService#updateCustomer(com.cafe.model.Customer)
	 */
	@Override
	public void updateCustomer(Customer customer) {
		customerDao.update(customer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param id
	 * 
	 * @see com.cafe.business.CustomerService#deleteCustomerById(long)
	 */
	@Override
	public void deleteCustomerById(int id) {
		customerDao.deleteByKey(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @param criteria
	 * 
	 * @param page
	 * 
	 * @see
	 * com.cafe.business.CustomerService#listByPage(org.hibernate.criterion.
	 * DetachedCriteria, com.malamute.core.common.Page)
	 */
	@Override
	public void listCustomersByPage(DetachedCriteria criteria, Page page) {
		customerDao.listByPage(criteria, page);
	}

	@Override
	public List findCustomersByUsername(DetachedCriteria criteria) {
		return customerDao.findByCriteria(criteria);
	}

}
